 import shoudata from '../data/shoudata'
 import javadata from '../data/javadata'
 import houdata from '../data/houdata'

const houduan ={
    //命名空间 作用就是划分清楚是谁的getters，mutations
    namespaced:true,
    state:{
        titleData: [
            {
              "id": 2546553,
              "tag_id": "6809640445233070094",
              "tag_name": "Java",
              "color": "#DD2C2A",
              "icon": "https://lc-gold-cdn.xitu.io/f8ee3cd45f949a546263.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 51381,
              "concern_user_count": 259734
            },
            {
              "id": 2546527,
              "tag_id": "6809640408797167623",
              "tag_name": "后端",
              "color": "#C679FF",
              "icon": "https://lc-gold-cdn.xitu.io/d83da9d012ddb7ae85f4.png",
              "back_ground": "",
              "show_navi": 1,
              "tag_alias": "",
              "post_article_count": 23121,
              "concern_user_count": 375105
            },
            {
              "id": 2546982,
              "tag_id": "6809641037787561992",
              "tag_name": "Spring Boot",
              "color": "#000000",
              "icon": "https://lc-gold-cdn.xitu.io/f77e4a02edb8b963a2c5.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 5401,
              "concern_user_count": 27595
            },
            {
              "id": 2546556,
              "tag_id": "6809640448827588622",
              "tag_name": "Python",
              "color": "#356E9C",
              "icon": "https://lc-gold-cdn.xitu.io/b51a1dacf9bb7883defe.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 17331,
              "concern_user_count": 195799
            },
            {
              "id": 2546494,
              "tag_id": "6809640364677267469",
              "tag_name": "Go",
              "color": "#64D7E3",
              "icon": "https://lc-gold-cdn.xitu.io/1aae38ab22d12b654cfa.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 5745,
              "concern_user_count": 77012
            },
            {
              "id": 2546740,
              "tag_id": "6809640703325372423",
              "tag_name": "Spring",
              "color": "#000000",
              "icon": "https://lc-gold-cdn.xitu.io/279e631b065a5a31289f.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 6410,
              "concern_user_count": 80561
            },
            {
              "id": 2546496,
              "tag_id": "6809640366896054286",
              "tag_name": "MySQL",
              "color": "#026088",
              "icon": "https://lc-gold-cdn.xitu.io/b2fbb06dce13eeb3bb9b.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 6677,
              "concern_user_count": 166491
            },
            {
              "id": 2546666,
              "tag_id": "6809640600502009863",
              "tag_name": "数据库",
              "color": "#000000",
              "icon": "https://lc-gold-cdn.xitu.io/c57a5426c2a8ab565881.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 8810,
              "concern_user_count": 247107
            },
            {
              "id": 2546499,
              "tag_id": "6809640371019055111",
              "tag_name": "Redis",
              "color": "#A51912",
              "icon": "https://lc-gold-cdn.xitu.io/4045af43b278afc7229b.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 4401,
              "concern_user_count": 129750
            },
            {
              "id": 2546592,
              "tag_id": "6809640499062767624",
              "tag_name": "算法",
              "color": "#60ADFF",
              "icon": "https://lc-gold-cdn.xitu.io/68a1097944c7fa1d7961.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 13670,
              "concern_user_count": 270850
            },
            {
              "id": 2546594,
              "tag_id": "6809640501776482317",
              "tag_name": "架构",
              "color": "#C679FF",
              "icon": "https://lc-gold-cdn.xitu.io/f27d811ad7e2b2a0bc24.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 8108,
              "concern_user_count": 297524
            },
            {
              "id": 2546735,
              "tag_id": "6809640696455102472",
              "tag_name": "JVM",
              "color": "#3b0a4c",
              "icon": "https://lc-gold-cdn.xitu.io/796f607b1e45a38c61f9.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 3413,
              "concern_user_count": 26194
            },
            {
              "id": 2546837,
              "tag_id": "6809640837895585805",
              "tag_name": "服务器",
              "color": "#a3abad",
              "icon": "https://lc-gold-cdn.xitu.io/be1879c7e9983dab0049.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 10166,
              "concern_user_count": 18051
            },
            {
              "id": 2546510,
              "tag_id": "6809640385980137480",
              "tag_name": "Linux",
              "color": "#616161",
              "icon": "https://lc-gold-cdn.xitu.io/b49dc843907aa7843a77.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 6627,
              "concern_user_count": 203908
            },
            {
              "id": 2546495,
              "tag_id": "6809640365574848526",
              "tag_name": "PHP",
              "color": "#777AB6",
              "icon": "https://lc-gold-cdn.xitu.io/7699e23cbe687eed8c38.png",
              "back_ground": "",
              "show_navi": 0,
              "tag_alias": "",
              "post_article_count": 5086,
              "concern_user_count": 87810
            }
        ],
        listData:[
          {
            id:-1,
            data:shoudata
          },
          {
            id:0,
            data:javadata
          },
          {
            id:1,
            data:houdata
          }
        ],
        id:-1,
        houId:0,
        brr:[]
    },
    getters:{
      filterData(state){
        let arr =JSON.parse(JSON.stringify(state.listData.filter(item=>item.id==state.id)))
        if(state.houId==0){
          arr[0].data.sort((a,b)=>{
            return a.article_info.hot_index-b.article_info.hot_index
        })
      return arr
        }else if(state.houId==1){
          arr[0].data.sort((a,b)=>{
                return a.article_info.ctime-b.article_info.ctime
            })
          return arr
        }else{
          arr[0].data.sort((a,b)=>{
                return b.article_info.digg_count-a.article_info.digg_count
            })
            console.log(arr)
            return arr
        }
      },
      
    },
    mutations:{
        //修改state里的id
        changeId(state,payload){
          let {key} = payload
          state.id=key
        },
        //点赞功能
        addDigg(state,payload){
          let {id,key} = payload
          state.listData.map((item)=>{
            if(item.id==id){
              if(item.data[key].num){
                return
              }else{
                item.data[key].article_info.digg_count+=1
              }
              item.data[key].num=1
              
            }
          })
        },
        changehouId(state,payload){
          let {key} = payload
          state.houId=key
      },
    }
}
export default houduan
